<?php

namespace app\models;

use think\Model;

class MpModel extends Model
{
    protected $table = 'edu_mp';

    /**
     * User: wufeng
     * Date: 2020/03/21.
     *
     * @param $params
     *
     * @throws \think\exception\DbException
     *
     * @return array
     */
    public function getMpLists($params)
    {
        $page = isset($params['page']) ? (int) $params['page'] : 1;
        $listRows = isset($params['limit']) ? (int) $params['limit'] : 10;
        $where = [];
        if (isset($params['mp_name']) && '' !== $params['mp_name']) {
            $where['mp_name'] = ['like', $params['mp_name'].'%'];
        }
        if (isset($params['status']) && '' !== $params['status']) {
            $where['status'] = $params['status'];
        }
        $listData = self::where($where)
            ->paginate($listRows, false, ['page' => $page])
            ->toArray();
        if (!empty($listData)) {
            foreach ($listData['data'] as &$item) {
                if (0 === (int) $item['status']) {
                    $item['status_text'] = '禁用中';
                } elseif (1 === (int) $item['status']) {
                    $item['status_text'] = '启用中';
                }
            }
        }

        return $listData;
    }
}
